package com.nacrtstudio.webgiftshop.pages;

import java.util.List;

import org.apache.tapestry5.annotations.InjectPage;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.services.Request;

import com.nacrtstudio.webgiftshop.facade.Controller;
import com.nacrtstudio.webgiftshop.model.shop.Gift;

public class Gifts {
	@Inject
	private Request request;
	public void onActivate() {
		try {
			if (controller.getRequest()==null) {
	    		controller.setRequest(request);
			}
		} catch (Exception e) {
		}
	}

	@Inject
	private Controller controller;
	@InjectPage
	private GiftInfo giftInfo;
	@InjectPage
	private Signin signinPage;
	@Property
	private Gift gift;
	public List<Gift> getAllGifts(){
		return controller.getSortedGifts();
	}
	
	Object onActionFromShow(Long id){
		giftInfo.setGift(controller.findGift(id));
    	return giftInfo;
    }
	
	Object onActionFromAddToShoopingCard(Long id){
    	if (controller.getLoggedSignal()) {
    		return controller.addGiftToCart(id);
		}
    	signinPage.setMessage("Niste prijavljeni! Molimo Vas da se prijavite ili registrujete.");
    	return signinPage;
    }
}
